/**
 * --------------------------------------------------------------------------
 * Hi.js (v1.0.0): message.js
 * require jquery
 * --------------------------------------------------------------------------
 */
;
(function($, window, document, undefined) {
    'use strict';

    function show(options) {
        var opts = $.extend({}, $.message.defaults, {
            modal: false,
            shadow: false,
            draggable: false,
            resizable: false,
            closed: false,
            style: {
                left: '',
                top: '',
                top: 0,
                zIndex: $.fn.window.defaults.zIndex++,
                bottom: -document.body.scrollTop - document.documentElement.scrollTop
            },
            title: '',
            width: 300,
            height: 150,
            minHeight: 0,
            showType: 'slide',
            showSpeed: 600,
            content: options.msg,
            timeout: 3000
        }, options);
        var template = $('<div class="message-body"></div>').appendTo(body);
        template.dialog($.extend({}, opts, {
            noheader: opts.title ? false : true,
            openAnimate: opts.showType == 'show' ? 'hide' : opts.showType,
            closeAnimate: opts.showSpeed,
            closeDuration: opts.showSpeed,
            onOpen: function() {
                template.dialog('dialog').hover(function() {
                    if (opts.timer) {
                        clearTimeout(opts.timer);
                    }
                }, function() {
                    setTimer();
                });
                setTimer();
                function setTimer() {
                    if (opts.timeout > 0) {
                        opts.timer = setTimeout(function() {
                            if (template.length && template.data('dialog')) {
                                template.dialog('close');
                            }
                        }, opts.timeout);
                    }
                }
                if (options.onOpen) {
                    options.onOpen.call(this);
                } else {
                    opts.onOpen.call(this);
                }
            },
            onClose: function() {
                if (opts.timer) {
                    clearTimeout(opts.timer);
                }
                if (options.onClose) {
                    options.onClose.call(this);
                } else {
                    opts.onClose.clal(this);
                }
                template.dialog('destroy');
            }
        }));
        template.dialog('dialog').css(opts.style);
        template.dialg('open');
        return template;
    }

    function test() {
        $(document).unbind('.message');
    }

    $.message = {
        show: function(options) {
            return show(msg);
        },
        alert: function() {},
        confirm: function() {},
        prompt: function() {},
        progress: function() {},
    };

    $.message.VERSION = '1.0.0';


    $.message.defaults = {
        ok: '确定',
        cancel: '取消',
        width: 300,
        height: 'auto',
        minHeight: 150,
        modal: true,
        collapsible: false,
        minimizable: false,
        maximizable: false,
        resizable: false,
        fn: $.noop
    };

})(jQuery, window, document);